package com.kmfish.smsbackup;

import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.provider.ContactsContract;

/**
 * 文件名	： 	ContactsUtil.java
 * @author	: 	lijun
 * 维护人	： 		
 * 创建时间	：	2011-5-26 下午07:38:24
 * 功能描述	:   get contact detail info.
 */
public class ContactsUtil {
	public static final String TAG = "SmsUtil";
	public static final Uri CONTACTS_CONTENT_URI = ContactsContract.Contacts.CONTENT_URI;
	
	
	public static MyContact getContactDetails(Context context, String number) {
		String WHERE_CONDITION =  ContactsContract.CommonDataKinds.Phone.NUMBER + " = '" + number + "'"; 
		Cursor cursor = context.getContentResolver().query(
				ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
				null, WHERE_CONDITION, null, null);

		if (null != cursor && cursor.getCount() > 0) {
			cursor.moveToPosition(0);
			MyContact contact = new MyContact();
			String name = cursor.getString(cursor
					.getColumnIndex(ContactsContract.PhoneLookup.DISPLAY_NAME));// contact
																				// name
			contact.name = name;
			contact.phone = new String[] { number };
			return contact;
		}
		return null;
	}
}
